// components/video/video.js
Component({
  /**
   * 组件的属性列表
   */
  options: {
    addGlobalClass: true,
  },
  properties: {
    videoCover: {
      type: String,
      value: ''
    },
    videoSrc: {
      type: String,
      value: ''
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    status: 'pause',
    playStatus: '/images/myicon/play.png',
    display: 'block',
    videoContext: null,
    isFullScreen: false
  },
  observers: {
    'videoCover, videoSrc': function (cover, src) {
      if (this.data.videoContext) {
        this.data.videoContext.stop()
        this.setData({
          status: 'pause',
          playStatus: '/images/myicon/play.png'
        })
        this.data.videoContext.seek(0)
      }
    }
  },
  /**
   * 组件的方法列表
   */

  methods: {
    ended() {
      this.setData({
        display: 'block',
        playStatus: '/images/myicon/play.png'
      })
    },
    bindcontrolstoggle(e) {
      console.log(e.detail)
      let isShow = e.detail.show ? 'block' : 'none'
      this.setData({
        display: isShow
      })
    },
    setPlay() {
      if (this.data.status === 'pause') {
        this.setData({
          status: 'playing',
          playStatus: '/images/myicon/zanting.png'
        })
        this.data.videoContext.play()

      } else {
        this.setData({
          status: 'pause',
          playStatus: '/images/myicon/play.png'
        })
        this.data.videoContext.pause()
      }
    }
  },
  lifetimes: {
    attached: function () {
      // 在组件实例进入页面节点树时执行
      let videoContext = wx.createVideoContext('videoPlay', this)
      this.setData({
        videoContext
      })

    },
    detached: function () {
      // 在组件实例被从页面节点树移除时执行
    },
  }
})